import Taro, { Component } from '@tarojs/taro'
import { View, Text ,Radio, RadioGroup, Label, Button, WebView} from '@tarojs/components'
import './blank.css'
import { AtButton, AtToast } from 'taro-ui'
import { fail } from 'assert';
import { STATUS_CODES } from 'http';
import app from '../../../main';

export default class Start extends Component {

  config = {
    navigationBarTitleText: '首页'
  }

  constructor(){
    super(...arguments);
  }

  onload() {
    console.log('加载成功--公众号授权页');
    let me = this;
    setTimeout(function () {
      app.get("web/doctor/get", {}, function (res) {
        app.current = res.data.result
        if (app.isEmpty(app.current)) {
          app.current = {};
        }
        var auth_status = app.current.auth_status;
        if (app.isEmpty(auth_status)) {
          auth_status = '未认证';
        }
        let userInfo = app.current
        console.log('决定去哪里', app.current)

        if (app.isEmpty(userInfo.head_image) || app.isEmpty(userInfo.nickname) || app.isEmpty(userInfo.phone)) {
          //没登录的跳转去登录提示页面
          app.redirectTo('/pages/doctorpages/firstEntry/firstEntry');
        } else if (auth_status == '未认证') { //跳转去填写资料
          app.redirectTo('/pages/center/pages/doctorcertified/doctorcertified');
        } else if (auth_status == '申请中' || auth_status == '审核不通过') {
          this.redirectTo('/pages/center/pages/doctorstatus/doctorstatus');
        } else {
          app.redirectTo('/pages/doctorpages/homepage/homepage');
        }
        
        me.setState({
          info: app.current
        });
      });

    }, 100)
    app.decidePage(app.current);
  }

  componentWillMount () {
    
  }

  componentDidMount () {}

  componentWillUnmount () { }

  componentDidShow () { }

  componentDidHide () { }
   
  render () {
    return (
      <WebView onLoad={this.onload.bind(this)} src={app.apiUri + '/web/weixin/getMemberOpenid?id='+app.current.id}  />
    )
  }
}

